<template>
	<view class="home-page">
		<navigation :navigationMsg="navigationMsg"></navigation>
		<view class="box">
			<!-- 搜索 -->
			<view class="search">
				<u-search bgColor="white" height="45" placeholder="请输入饰品关键字" :showAction="false" v-model="searchText"
					@search="search"></u-search>
			</view>

			<!-- 公告 -->
			<announcement></announcement>
			<swiperVue></swiperVue>
			<!-- 首页列表 -->
			<view class="list-box">
				<view class="top">
					<view class="left">最新上架</view>
					<view class="right">更多&nbsp;&gt;</view>
				</view>
				<view class="list">
					<view class="list-item" v-for="(item,index) in dataList" @click="go_detailType(item,index)">
						<view class="imgbox">
							<view class="img" :style="{ backgroundImage: 'url(' + item.image + ')' }"></view>
							<!-- <view class="wear">
								<view class="type" style="background-color: red;"></view>
								<view class="text">
									<span style="color:green;" v-if="item.wear=='崭新出场'">崭新出场</span>
									<span style="color:#5cb85c;" v-if="item.wear=='略有磨损'">略有磨损</span>
									<span style="color:#f0ad4e;" v-if="item.wear=='久经沙场'">久经沙场</span>
									<span style="color:#d9534f;" v-if="item.wear=='残破不堪'">残破不堪</span>
									<span style="color:#993A38;" v-if="item.wear=='战痕累累'">战痕累累</span>
								</view>
							</view> -->
						</view>
						<view class="msg">
							<view class="top">
								<view class="name">{{item.name}}({{item.wear}})</view>
							</view>
							<view class="bottom">
								<view class="price">￥{{item.price}}</view>
								<view class="sum">在售{{item.hobbydata}}件</view>
							</view>
						</view>
					</view>
				</view>
				<view class="bah">
					备案号：{{copyRight}}
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	import navigation from '../../components/navigation.vue'
	import announcement from '../../components/index/announcement.vue';
	import swiperVue from '../../components/index/swiper.vue';
	export default {
		data() {
			return {
				navigationMsg: {
					title: "市场"
				},
				searchText: "",
				dataList: [],
				pageNum: 1,
				//备案号
				copyRight: ""
			}
		},
		components: {
			navigation,
			announcement,
			swiperVue
		},
		mounted() {
			this.getList(this.pageNum)
			this.getSetting()
			this.isMobile()
		},
		methods: {
			// isMobile() {
			// 	// 判断是否PC端访问
			// 	var isMobile = /Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent);
			// 	var inIframe = window.frames.length != parent.frames.length;
			// 	// PC端访问且不在iframe内时跳转到pc.html
			// 	if (!isMobile && !inIframe) {
			// 		const url = window.location.href
			// 		window.location.href = `${url}index2.html`
			// 		uni.setStorageSync('url', `${url}`)
			// 	}
			// },
			getSetting() {
				uni.request({
					url: "/api/index/getSetting",
					method: "POST"
				}).then(res => {
					this.copyRight = res.data.data.copyRight;
					uni.setStorageSync('site_name', res.data.data.site_name)
				})
			},
			getList(pageNum) {
				let data = {
					page: pageNum,
					index: "home",
					limit: 2
				}
				uni.request({
					url: "/api/jewerly/apiJewerly",
					method: "POST",
					data: data
				}).then((res) => {
					// console.log(res.data.data, "data")
					this.dataList = res.data.data
					// if (nextOrderList.length > 0) {
					// 	this.dataList = this.dataList.concat(nextOrderList)
					// 	this.pageNum++
					// 	// console.log(this.pageNum);
					// } else {
					// 	uni.showToast({
					// 		title: "没有更多了",
					// 		icon: "none"
					// 	})
					// }
				})
			},
			//搜索
			search() {
				// console.log(this.searchText);
			},
			//商品种类页
			go_detailType(item, index) {
				let token = uni.getStorageSync('token')
				if (!token) {
					uni.navigateTo({
						url: "/pages/login/login"
					})
					return
				} else {
					let data = {
						name: item.name,
						image: item.image,
						price: item.price
					}
					let msg = JSON.stringify(data)
					uni.navigateTo({
						url: `/pages/detail-type/detail-type?msg=${msg}`
					})
				}

			}
		}
	}
</script>
<style lang="scss" scoped>
	.home-page {
		width: 100vw;
		height: 100vh;
		background-color: #f4f5f7;
		display: flex;
		flex-direction: column;
		align-items: center;
		overflow-y: scroll;

		.box {
			width: 90%;
			height: 81vh;


			.search {
				width: 100%;
				height: 11vw;
				margin-top: 3vw;
			}

			.list-box {
				width: 100%;
				margin-top: 5vw;

				.top {
					width: 100%;
					height: 10vw;
					display: flex;
					justify-content: space-between;
					align-items: center;

					.left {
						font-size: 5vw;
						font-weight: bold;
					}

					.right {
						color: #b0b0b1;
					}
				}

				.list {
					width: 100%;
					display: flex;
					flex-wrap: wrap;

					.list-item {
						width: 43vw;
						height: 50vw;
						background-color: white;
						border-radius: 1vw;
						margin-top: 3vw;
						overflow: hidden;

						.imgbox {
							width: 100%;
							height: 28vw;
							background-image: linear-gradient(to top, #999999, #ccc);
							position: relative;

							.img {
								width: 100%;
								height: 28vw;
								background-size: contain;
								background-position: center;
								background-repeat: no-repeat;
							}

							.wear {
								position: absolute;
								width: 15vw;
								height: 5vw;
								top: 0;
								left: 0;
								display: flex;

								.type {
									width: 2vw;
									height: 5vw;
								}

								.text {
									width: 13vw;
									height: 5vw;
									background-color: black;
									font-size: 3vw;
									display: flex;
									justify-content: center;
									align-items: center;
									font-weight: bold;
								}
							}
						}

						.msg {
							width: 100%;
							height: 22vw;

							.top {
								width: 100%;
								height: 11vw;

								.name {
									width: 100%;
									height: 6vw;
									font-size: 4.5vw;
									font-weight: bold;
									white-space: nowrap;
									overflow: hidden;
									text-overflow: ellipsis;
									text-indent: 1vw;
								}
							}

							.bottom {
								width: 100%;
								height: 11vw;
								display: flex;
								justify-content: space-between;
								align-items: center;

								.price {
									font-size: 4.5vw;
									font-weight: bold;
									color: #EEA20E;
									margin-left: 2vw;
								}

								.sum {
									color: #ccc;
									font-size: 3vw;
									margin-right: 2vw;
								}
							}
						}
					}

					.list-item:nth-child(2n) {
						margin-left: 4vw;
					}
				}

				.bah {
					width: 90%;
					margin: auto;
					height: 20vw;
					line-height: 20vw;
					color: #999999;
					text-align: center;
				}
			}
		}
	}
</style>